﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Data.SqlClient;

public partial class SchemaDB_ShowModels : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // get manufacturer url
        var url = this.Request.Params["ManufacturerUrl"];

        if (string.IsNullOrEmpty(url))
            throw new ArgumentException("missing 'ManufacturerUrl' parameter in request");

        // get manufacturer name
        using (var conn = new SqlConnection(Settings.ConnectionString))
        {
            conn.Open();

            var cmd = new SqlCommand()
            {
                Connection = conn,
                CommandType = System.Data.CommandType.Text,
                CommandText = "select top 1 Manufacturer from DeviceDom where ManufacturerUrl=@url"

            };

            cmd.Parameters.AddWithValue("@url", url);
            
            var manuName = cmd.ExecuteScalar().ToString();

            this.Manufacturer.InnerHtml = string.Format(
                "<a href=\"{1}\" target=\"_blank\">{0}</a>",
                manuName,
                url
                );
        }

        // bind to report
        var p = new[] { new ReportParameter("ManufacturerUrl", url) };

        this.ReportViewer1.LocalReport.SetParameters(p);
    }
}
